package com.study.d015propertybind.fx;

import java.util.Iterator;
import java.util.Set;

import javafx.beans.property.SimpleSetProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
import javafx.collections.SetChangeListener;

/**
*@description SimpleSetProperty绑定的使用
*@author xtayhame
*date 2020年3月5日
*version
*since v1.0
*/
public class SimpleSetPropertyMain {
	public static void main(String[] args) {
		ObservableSet<String> set=FXCollections.observableSet("A","B","C");
		SimpleSetProperty<String> ssp = new SimpleSetProperty<String>(set);

		//添加监听1
		ssp.addListener(new ChangeListener<ObservableSet<String>>() {
			@Override
			public void changed(ObservableValue<? extends ObservableSet<String>> observable,
					ObservableSet<String> oldValue, ObservableSet<String> newValue) {
				System.out.println("oldValue="+oldValue);
				System.out.println("newValue="+newValue);
			}
		});


		//添加监听2
		ssp.addListener(new SetChangeListener<String>() {
			@Override
			public void onChanged(javafx.collections.SetChangeListener.Change<? extends String> change) {
				ObservableSet set1= change.getSet();
				Iterator<String> it=set1.iterator();
				while(it.hasNext()){
					System.out.println(it.next());
				}
			}
		});

		ssp.add("E");


	}
}
